/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.uch.util;

import java.util.List;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;

/**
 *
 * @author USUARIO
 */
public class CommonWeb {

    public static String getParamFromUI( String sNomParam ) {
       String sParam;
       try {
           FacesContext context = FacesContext.getCurrentInstance();
           sParam = context.getExternalContext().getRequestParameterMap().get( sNomParam );
       } catch ( Exception ex ) {
           sParam = "";
           ex.printStackTrace();
       }
       return sParam;
   }
    
   /* public static String getParamFromUI ( ActionEvent event, String sNomParam ) {
        String sParam;
        try {
//            sParam = ((UIParameter) event.getComponent().findComponent( sNomParam )).getValue().toString();
            FacesContext context = FacesContext.getCurrentInstance();
            sParam = context.getExternalContext().getRequestParameterMap().get( sNomParam );

        } catch ( Exception ex ) {
            sParam = "";
            ex.printStackTrace();
        }

        return sParam;
    }

    public static SelectItem[] getCboArbolAreaInf ( int iArbIdPadre ) {
       SelectItem[] cboArea;
      
            List<ClArbolAcademico> lista = CommonDAO.getClArbolAcademicoDAO().listarArbolPorPadre( 0 );
            cboArea = new SelectItem[lista.size() + 1];
            cboArea[0] = new SelectItem("0", "[Seleccionar área]");
            for (int i = 0; i < (cboArea.length - 1); i++) {
                cboArea[i + 1] = new SelectItem(lista.get(i).getArbId(), lista.get(i).getArbDescripcion());
            }
        return cboArea;
    }
    
    public static SelectItem[] getCboArbolModInf ( int iArbIdPadre ) {
        SelectItem[] cboArbol;
        
        cboArbol = new SelectItem[ 1 ];
        cboArbol[0] = new SelectItem( "0", "[Seleccione]" );
        
        if ( iArbIdPadre != 0 ) {
            List<ClArbolAcademico> lstModulo = CommonDAO.getClArbolAcademicoDAO().listarArbolPorPadre( iArbIdPadre );
            if ( lstModulo != null && !lstModulo.isEmpty() ) {
                
                
                cboArbol = new SelectItem[ lstModulo.size() + 1 ];
                cboArbol[0] = new SelectItem( "0", "[Seleccione]" );
                for ( int i = 0; i < (cboArbol.length - 1); i++ ) {
                    cboArbol[i + 1] = new SelectItem( lstModulo.get( i ).getArbId(), lstModulo.get( i ).getArbDescripcion() );
                }
            }
        }
        return cboArbol;
    }
    
    public static SelectItem[] getCboArbolCursoInf ( int iArbIdPadre ) {
        SelectItem[] cboArbol;

        cboArbol = new SelectItem[ 1 ];
        cboArbol[0] = new SelectItem( "0", "[Seleccione]" );

        if ( iArbIdPadre != 0 ) {
            List<ClArbolAcademico> lstModulo = CommonDAO.getClArbolAcademicoDAO().listarArbolPorPadre( iArbIdPadre );
            if ( lstModulo != null && !lstModulo.isEmpty() ) {

                cboArbol = new SelectItem[ lstModulo.size() + 2 ];
                cboArbol[0] = new SelectItem( "0", "[Seleccione]" );
                cboArbol[1] = new SelectItem( "-1", "NO DETERMINADO" );
                for ( int i = 0; i < (cboArbol.length - 2); i++ ) {
                    cboArbol[i + 2] = new SelectItem( lstModulo.get( i ).getArbId(), lstModulo.get( i ).getArbDescripcion() );
                }
            }
        }
        return cboArbol;
    }
    
    */
}
